/*
 * Selling Partner API for Orders
 *
 * Use the Orders Selling Partner API to programmatically retrieve order information. With this API, you can develop fast, flexible, and custom applications to manage order synchronization, perform order research, and create demand-based decision support tools.   _Note:_ For the JP, AU, and SG marketplaces, the Orders API supports orders from 2016 onward. For all other marketplaces, the Orders API supports orders for the last two years (orders older than this don't show up in the response).
 *
 * The version of the OpenAPI document: v0
 * Generated by: https://github.com/openapitools/openapi-generator.git
 */


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.IO;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = software.amzn.spapi.Client.OpenAPIDateConverter;

namespace software.amzn.spapi.Model.orders.v0
{
    /// <summary>
    /// Information about the prescription that is used to verify a regulated product. This must be provided once per order and reflect the seller’s own records. Only approved orders can have prescriptions.
    /// </summary>
    [DataContract(Name = "PrescriptionDetail")]
    public partial class PrescriptionDetail : IValidatableObject
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PrescriptionDetail" /> class.
        /// </summary>
        [JsonConstructorAttribute]
        protected PrescriptionDetail() { }
        /// <summary>
        /// Initializes a new instance of the <see cref="PrescriptionDetail" /> class.
        /// </summary>
        /// <param name="prescriptionId">The identifier for the prescription used to verify the regulated product. (required).</param>
        /// <param name="expirationDate">The expiration date of the prescription used to verify the regulated product, in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date time format. (required).</param>
        /// <param name="writtenQuantity">The number of units in each fill as provided in the prescription. (required).</param>
        /// <param name="totalRefillsAuthorized">The total number of refills written in the original prescription used to verify the regulated product. If a prescription originally had no refills, this value must be 0. (required).</param>
        /// <param name="refillsRemaining">The number of refills remaining for the prescription used to verify the regulated product. If a prescription originally had 10 total refills, this value must be &#x60;10&#x60; for the first order, &#x60;9&#x60; for the second order, and &#x60;0&#x60; for the eleventh order. If a prescription originally had no refills, this value must be 0. (required).</param>
        /// <param name="clinicId">The identifier for the clinic which provided the prescription used to verify the regulated product. (required).</param>
        /// <param name="usageInstructions">The instructions for the prescription as provided by the approver of the regulated product. (required).</param>
        public PrescriptionDetail(string prescriptionId = default(string), DateTime expirationDate = default(DateTime), int writtenQuantity = default(int), int totalRefillsAuthorized = default(int), int refillsRemaining = default(int), string clinicId = default(string), string usageInstructions = default(string))
        {
            // to ensure "prescriptionId" is required (not null)
            if (prescriptionId == null)
            {
                throw new ArgumentNullException("prescriptionId is a required property for PrescriptionDetail and cannot be null");
            }
            this.PrescriptionId = prescriptionId;
            this.ExpirationDate = expirationDate;
            this.WrittenQuantity = writtenQuantity;
            this.TotalRefillsAuthorized = totalRefillsAuthorized;
            this.RefillsRemaining = refillsRemaining;
            // to ensure "clinicId" is required (not null)
            if (clinicId == null)
            {
                throw new ArgumentNullException("clinicId is a required property for PrescriptionDetail and cannot be null");
            }
            this.ClinicId = clinicId;
            // to ensure "usageInstructions" is required (not null)
            if (usageInstructions == null)
            {
                throw new ArgumentNullException("usageInstructions is a required property for PrescriptionDetail and cannot be null");
            }
            this.UsageInstructions = usageInstructions;
        }

        /// <summary>
        /// The identifier for the prescription used to verify the regulated product.
        /// </summary>
        /// <value>The identifier for the prescription used to verify the regulated product.</value>
        [DataMember(Name = "prescriptionId", IsRequired = true, EmitDefaultValue = true)]
        public string PrescriptionId { get; set; }

        /// <summary>
        /// The expiration date of the prescription used to verify the regulated product, in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date time format.
        /// </summary>
        /// <value>The expiration date of the prescription used to verify the regulated product, in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) date time format.</value>
        [DataMember(Name = "expirationDate", IsRequired = true, EmitDefaultValue = true)]
        public DateTime ExpirationDate { get; set; }

        /// <summary>
        /// The number of units in each fill as provided in the prescription.
        /// </summary>
        /// <value>The number of units in each fill as provided in the prescription.</value>
        [DataMember(Name = "writtenQuantity", IsRequired = true, EmitDefaultValue = true)]
        public int WrittenQuantity { get; set; }

        /// <summary>
        /// The total number of refills written in the original prescription used to verify the regulated product. If a prescription originally had no refills, this value must be 0.
        /// </summary>
        /// <value>The total number of refills written in the original prescription used to verify the regulated product. If a prescription originally had no refills, this value must be 0.</value>
        [DataMember(Name = "totalRefillsAuthorized", IsRequired = true, EmitDefaultValue = true)]
        public int TotalRefillsAuthorized { get; set; }

        /// <summary>
        /// The number of refills remaining for the prescription used to verify the regulated product. If a prescription originally had 10 total refills, this value must be &#x60;10&#x60; for the first order, &#x60;9&#x60; for the second order, and &#x60;0&#x60; for the eleventh order. If a prescription originally had no refills, this value must be 0.
        /// </summary>
        /// <value>The number of refills remaining for the prescription used to verify the regulated product. If a prescription originally had 10 total refills, this value must be &#x60;10&#x60; for the first order, &#x60;9&#x60; for the second order, and &#x60;0&#x60; for the eleventh order. If a prescription originally had no refills, this value must be 0.</value>
        [DataMember(Name = "refillsRemaining", IsRequired = true, EmitDefaultValue = true)]
        public int RefillsRemaining { get; set; }

        /// <summary>
        /// The identifier for the clinic which provided the prescription used to verify the regulated product.
        /// </summary>
        /// <value>The identifier for the clinic which provided the prescription used to verify the regulated product.</value>
        [DataMember(Name = "clinicId", IsRequired = true, EmitDefaultValue = true)]
        public string ClinicId { get; set; }

        /// <summary>
        /// The instructions for the prescription as provided by the approver of the regulated product.
        /// </summary>
        /// <value>The instructions for the prescription as provided by the approver of the regulated product.</value>
        [DataMember(Name = "usageInstructions", IsRequired = true, EmitDefaultValue = true)]
        public string UsageInstructions { get; set; }

        /// <summary>
        /// Returns the string presentation of the object
        /// </summary>
        /// <returns>String presentation of the object</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("class PrescriptionDetail {\n");
            sb.Append("  PrescriptionId: ").Append(PrescriptionId).Append("\n");
            sb.Append("  ExpirationDate: ").Append(ExpirationDate).Append("\n");
            sb.Append("  WrittenQuantity: ").Append(WrittenQuantity).Append("\n");
            sb.Append("  TotalRefillsAuthorized: ").Append(TotalRefillsAuthorized).Append("\n");
            sb.Append("  RefillsRemaining: ").Append(RefillsRemaining).Append("\n");
            sb.Append("  ClinicId: ").Append(ClinicId).Append("\n");
            sb.Append("  UsageInstructions: ").Append(UsageInstructions).Append("\n");
            sb.Append("}\n");
            return sb.ToString();
        }

        /// <summary>
        /// Returns the JSON string presentation of the object
        /// </summary>
        /// <returns>JSON string presentation of the object</returns>
        public virtual string ToJson()
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
        }

        /// <summary>
        /// To validate all properties of the instance
        /// </summary>
        /// <param name="validationContext">Validation context</param>
        /// <returns>Validation Result</returns>
        IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
        {
            // WrittenQuantity (int) minimum
            if (this.WrittenQuantity < (int)1)
            {
                yield return new ValidationResult("Invalid value for WrittenQuantity, must be a value greater than or equal to 1.", new [] { "WrittenQuantity" });
            }

            // TotalRefillsAuthorized (int) minimum
            if (this.TotalRefillsAuthorized < (int)0)
            {
                yield return new ValidationResult("Invalid value for TotalRefillsAuthorized, must be a value greater than or equal to 0.", new [] { "TotalRefillsAuthorized" });
            }

            // RefillsRemaining (int) minimum
            if (this.RefillsRemaining < (int)0)
            {
                yield return new ValidationResult("Invalid value for RefillsRemaining, must be a value greater than or equal to 0.", new [] { "RefillsRemaining" });
            }

            yield break;
        }
    }

}
